/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package starwarslife;

import sun.tools.jar.resources.jar;
import userinterface.GameFrame;

/**
 *
 * @author Yann
 */
public class SWLController {
    
    private SWLModel model;
    private GameFrame gameFrame;
    private int[][] bs;
    GameThread gt;
    private boolean fresh = true;
    
    public SWLController(SWLModel model){
        this.model = model;
    }

    public void start() {
        if(fresh){
            fresh = false;
            setInitialPositions();
            gameFrame.setBoardState(bs);
        }
        gt = new GameThread(this, bs);
        gt.start();
    }

    public void pause() {
        gt.gracefullyStop();
    }
    
    public void setGameFrame(GameFrame gf){
        gameFrame = gf;
    }
    
    private void setInitialPositions(){
        bs = gameFrame.getBoardState();
        resetBoardState();
        bs[0][0] = 1;
        gameFrame.setBoardState(bs);
    }

    public void setBoardState(int[][] bs) {
        this.bs = bs;
        gameFrame.setBoardState(bs);
    }

    public void reset() {
        pause();
        resetBoardState();
        gameFrame.setBoardState(bs);
        fresh=true;
    }

    private void resetBoardState() {
        for (int i = 0; i < bs.length; i++)
            for (int j = 0; j < bs[i].length; j++) bs[i][j] = 0;
    }
    
    
}